import docx


def getText(filename):
    doc = docx.Document(filename)
    fullText = []
    for p in doc.paragraphs:
        fullText.append(p.text)
    return '\n'.join(fullText)


# mydoc = docx.Document('demo.docx')
# print(len(mydoc.paragraphs))
# print(mydoc.paragraphs[4].text)
#
# print(len(mydoc.paragraphs[1].runs))
#
# print(mydoc.paragraphs[1].runs[4].text)

# print(getText('demo.docx'))

def setStyle(filename):
    doc = docx.Document(filename)
    print(doc.paragraphs[0].text)
    doc.paragraphs[0].style = 'Normal'
    print(doc.paragraphs[1].text)
    doc.paragraphs[1].runs[0].style = 'QuoteChar'
    doc.paragraphs[1].runs[1].underline = True
    doc.paragraphs[1].runs[3].underline = True
    doc.save('restyled.docx')


# setStyle('demo.docx')


def add(filename):
    doc = docx.Document(filename)
    doc.add_paragraph('hello,world')
    paraObj1 = doc.add_paragraph('This is a second paragraph.')
    paraObj2 = doc.add_paragraph('This is a yet another paragraph.')
    paraObj1.add_run(' This text is being added to the second paragraph.')
    doc.save('multiParagrahs.docx')


# add('demo.docx')

def addHeading():
    doc = docx.Document()
    doc.add_heading('Header', 0)
    doc.add_heading('Header1', 1)
    doc.add_heading('Header2', 2)
    doc.add_heading('Header3', 3)
    doc.add_heading('Header4', 4)
    doc.save('headings.docx')


# addHeading()

def addbreak():
    doc = docx.Document()
    doc.add_paragraph('this is on the first page.')
    doc.add_paragraph('hello,every one.')
    doc.paragraphs[1].runs[0].add_break(docx.enum.text.WD_BREAK.PAGE)
    doc.add_paragraph('this is on the second page')
    doc.save('towpage.docx')
addbreak()
